<template>
    <div style="background: #fff">
        <div class="personal">
            <div class="personal_box">
                <div class="personal_box_left" v-if="user">
                    <img :src="user.avatar">
                    <div class="-list_user" style=" width: calc(100% - 128px);">
                        <p class="p1"><span>{{user.nickname}}</span><router-link :to="'/myzoe/zhuye/'+user.id">我的主页&gt;</router-link></p>
                        <p class="p2"><router-link class="attention" to="/myzoe/guanzhu"><span></span>关注{{focusnumber}}</router-link>
                            <router-link class="fans" to="/myzoe/fans"><span></span>粉丝{{fansnumber}}</router-link></p>
                    </div>
                </div>
                <img src="../../assets/img/scan.png" v-if="isapp" @click="scan()" class="scanimg" />
                <router-link class="personal-tiixan" to="/myzoe/tixian" style="color:white; display: block"><span> 提现</span></router-link>
                <!--<div class="personal_box_right"><span class="s1">可提现金额</span><span class="s2 red_ft">{{tixian.money}}</span></div>-->
                <div class="personal-addup_box">
                    <div class="addup">
                        <div class="d1">
                            <p>今日收益</p>
                            <span style="color: rgb(252, 93, 77);">￥{{earnings.todaymoney}}
                                <!--<img style="width: 12px;height: 12px" src="../../assets/img/money_icon.png"/>-->
                            </span>
                        </div>
                        <!--<div class="d2"><p>昨日收益</p><span>{{earnings.yesterdaymoney}}<i>元</i></span></div>-->
                        <div class="d2"><p>总收益</p><span>￥{{earnings.totalmoney}}
                            <!--<img style="width: 12px;height: 12px" src="../../assets/img/money_icon.png"/>-->
                        </span></div>
                        <div>
                            <!--<p>总收益</p><span>{{earnings.totalmoney}}<i>元</i></span>-->
                            <p>余额</p><span>￥{{tixian.money}}
                            <!--<img style="width: 12px;height: 12px" src="../../assets/img/money_icon.png"/>-->
                        </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!--<router-link class="personal-tiixan" to="/myzoe/tixian" style="color:white; display: block"><span> 提现</span></router-link>-->
        <!--<div class="personal-fans-attention-btn">-->
            <!--<router-link class="attention" to="/myzoe/guanzhu"><span></span>关注{{focusnumber}}</router-link>-->
            <!--<router-link class="fans" to="/myzoe/fans"><span></span>粉丝{{fansnumber}}</router-link>-->
        <!--</div>-->
        <div class="personal-lsit">
            <div class="box">
                <router-link :to="{path:item.name,query:{pagetitle:item.title}}" class="personal-lsit_btn" v-for="(item, index) in columns">
                    <p :style="'background: url('+Url+item.icon1+') no-repeat left center;background-size: 20px;'">
                        <span>{{item.title}}</span>
                        <i class="new_icon" v-if="item.ishot==1">
                            <!--<img src="">-->
                            <img src="../../assets/img/iconhot.png">
                        </i>
                    </p>
                </router-link>
                <div class="personal-lsit_btn" @click="loginOut()">
                    <p class="f-bac">
                        <span>刷新登录</span>
                    </p>
                </div>
            </div>
        </div>
        <!--<router-link class="personal-disclaimer" to="/myzoe/rule">服务条款/免责申明</router-link>-->
        <router-link class="personal-disclaimer" to="/myzoe/rule">平台使用协议</router-link>

        <footers name="/" v-if="loadfoot"></footers>
    </div>
</template>

<script>
    import footers from '@/components/footer';
    export default {
        name: "",
        components: {
            footers
        },
        data(){
            return {
                user:{},
                earnings:{},
                tixian:{},
                fwarticle:{},
                focusnumber:0,
                fansnumber:0,
                columns:[],
                tablist:[],
                loadfoot:false,
                isapp:false    //是否显示扫一扫
            }
        },
        mounted(){
//            localStorage.removeItem("token");
//            localStorage.setItem("token","e151d1aa-7a3d-47e6-80a6-774dbb9afed6");

            var token= localStorage.getItem("token");
            // console.log("token:"+token);
            if(!token){
                this.onloads()
            }else {
                this.getUser();
            }

            var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
            if (ua.match(/MicroMessenger/i) != "micromessenger") {
                this.isapp=true;
            }
            window.getRQData=this.getRQData;
        },
        methods:{
            scan(){
//                this.$toast("扫一扫");
                var u = navigator.userAgent;
                var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
                var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
;

                if(isiOS){
//                    this.$toast("这是苹果端");
//                    window.webkit.messageHandlers.hldq.postMessage('loadQRcode')
                    window.webkit.messageHandlers.loadQRcode.postMessage('loadQRcode')
                }else if(isAndroid){
//                    this.$toast("这是安卓端");
                    window.hldq.loadQRcode();
                }
            },
            getRQData(res){
//                alert(JSON.stringify(res))
                var url = this.Url + 'api' + res.match(/api(\S*)/)[1];
                location.href=url;
            },
            // 退出并重新登录
            loginOut(){
                localStorage.removeItem("token");
                this.onloads();
            },
            onloads(){
                var that=this;
                var ua = navigator.userAgent.toLowerCase();//获取判断用的对象

                if (ua.match(/MicroMessenger/i) == "micromessenger") {
                    console.log("wx打开");
                    this.getCode();
                }else {
                    console.log("h5打开");
                    that.$router.push("/log/login")
                }
            },
            getCode () {
                var that=this;
                var local = window.location.href;// 获取页面url
                that.code = that.getUrlCode().code; // 截取code
                if (that.code == null || that.code === '') { // 如果没有code，则去请求
                    that.$axios.post(that.Url+'api/index/getAppid',{
                        params:{},
                    }).then(function(res){
                        console.log(res)
                        if(res.data.code==1){
                            let ress=res.data.data;
                            let appid = ress.appid;
                            console.log("appid:"+appid);
                            window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
                        }
                    }).catch(function (error) {
                        console.log(error)
                    });
                } else {
                    that.login()
                }
                that.$axios.post(that.Url+'api/user.index/third',{code:that.code}
                ).then(function(res){
                    console.log(res);
                    if(res.data.code==1){
                        localStorage.setItem('token', res.data.data.userinfo.token);
                        that.getUser();
                        that.loadfoot=true;
//                        that.getTab();
                    }
                }).catch(function (error) {
                    console.log(error)
                });
            },
            getUrlCode() { // 截取url中的code方法
                var url = location.search;
                this.winUrl = url;
                var theRequest = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.substr(1);
                    var strs = str.split("&");
                    for(var i = 0; i < strs.length; i ++) {
                        theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
                    }
                }
                return theRequest;
            },
            login(){
                var that=this;
                that.$axios.post(that.Url+'api/user.index/third',{code:that.code}
                ).then(function(res){
                    console.log(res);
                    if(res.data.code==1){
                        localStorage.setItem('token', res.data.data.userinfo.token);
//                        location.href="http://hongdan.westts.cn/index.html#/";
                        that.getUser();
                        that.loadfoot=true;
//                        that.getTab();
                    }
                }).catch(function (error) {
                    console.log(error)
                });
            },
            getUser(){
                var that=this;
                that.request1.post1({
                    url: that.Url + "api/user.index/index",
                    params: {  },
                    success: function (res) {
                        console.log(res)
                        if (res.data.code == 1) {
                            that.user=res.data.data.user;
                            that.earnings=res.data.data.earnings;
                            that.tixian=res.data.data.tixian;
                            that.focusnumber=res.data.data.focusnumber;
                            that.fansnumber=res.data.data.fansnumber;
                            that.columns=res.data.data.columns;
                            that.loadfoot=true;
//                            if(!res.data.data.user.mobile && !sessionStorage.getItem("bindtelsession")){
//                                console.log("请绑定手机号");
//                                that.$router.push("/log/bindtel")
//                            }
                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        if (error.data.code == 401){
//                            console.log("没有token")
                            localStorage.removeItem("token");
                            that.onloads()
                        }
                        alert(error.data.msg)
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .f-bac{
        background: url("../../assets/img/login_out.png") no-repeat left center;
        background-size: 20px;
    }
    .personal {
        background: #f5533f;
        height: 152px;
        position: relative;
        margin-bottom: 42px;
    }
    .personal .personal_box {
        display: -webkit-box;
        height: 160px;
        position: absolute;
        width: 90%;
        background: #fff;
        border-radius: 14px;
        bottom: -33px;
        left: 5%;
        box-shadow: 0 2px 15px rgba(0,0,0,0.2);
    }
    .personal .personal_box .personal_box_left {
        -webkit-box-flex: 1;
        margin-left: 15px;
        margin-top: 26px;
    }
    .personal .personal_box .personal_box_left img {
        display: block;
        width: 48px;
        height: 48px;
        border-radius: 50px;
        float: left;
    }
    .personal .personal_box .personal_box_left > div {
        margin-left: 7px;
        float: left;
        margin-left: 5px;
    }
    .personal .personal_box .personal_box_left > div .p1 {
        font-size: 15px;
        font-weight: 700;
        line-height: 24px;
    }
    .personal .personal_box .personal_box_left > div .p1 span{
        max-width: calc(100% - 70px);
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: middle;
    }
    .personal .personal_box .personal_box_left > div .p2 {
        font-size: 12px;
        color: #999;
        display: block;
        line-height: 12px;
        font-weight: 700;
        margin-top: 8px;
    }
    .personal .personal_box .personal_box_left > div .p1 a{
        font-size: 12px;
        color: #4482e4;
        margin-left: 5px;
    }
    .personal .personal_box .personal_box_left > div .p2 a{
        font-size: 12px;
        margin-right: 20px;
        display: inline-block;
    }
    .personal .personal_box .personal_box_left > div .p2 .attention span {
        background: url() no-repeat 0;
        background-size: 14px;
        padding-left: 18px;
    }
    .personal .personal_box .personal_box_left > div .p2 .fans span {
        background: url() no-repeat 0;
        background-size: 14px;
        padding-left: 18px;
    }
    .personal .personal_box .personal_box_right {
        margin-right: 15px;
        margin-top: 22px;
    }
    .personal .personal_box .personal_box_right span.s1 {
        color: #999;
        padding-right: 2px;
        font-size: 12px;
        text-align: right;
        height: 12px;
        line-height: 12px;
        margin-bottom: 2px;
    }
    .personal .personal_box .personal_box_right span.s2 {
        font-size: 30px;
        height: 30px;
        line-height: 30px;
    }
    .red_ft {
        color: #fc5d4d !important;
    }
    .personal .personal_box .personal_box_right span {
        display: block;
    }
    .personal-addup_box {
        height: 55px;
        background: #fff;
        position: absolute;
        bottom: 0;
        width: 90%;
        left: 5%;
    }
    .personal-addup_box .addup {
        width: 100%;
        height: 50px;
        display: -webkit-box;
        border-radius: 8px;
    }
    .personal-addup_box .addup > div {
        -webkit-box-flex: 1;
        height: 40px;
        text-align: center;
        margin-top: 5px;
    }
    .personal-addup_box .addup > div.d1, .personal-addup_box .addup > div.d2 {
        border-right: 1px solid #f8f8f8;
    }
    .personal-addup_box .addup > div p {
        display: block;
        text-align: center;
        font-size: 12px;
        color: #999;
        height: 12px;
        line-height: 12px;
        padding-top: 4px;
    }
    .personal-addup_box .addup > div span {
        display: block;
        text-align: center;
        font-size: 18px;
        color: #999;
        height: 18px;
        line-height: 18px;
        padding-top: 2px;
    }
    .personal-addup_box .addup > div span i {
        font-size: 12px;
        font-style: normal;
    }
    .personal-tiixan {
        background: #f5533f;
        height:28px;
        line-height: 28px;
        text-align: center;
        border-radius: 4px;
        position: absolute;
        right: 12px;
        top: 32px;
        width: 60px;
    }
    .personal-tiixan span {
        display: inline-block;
        padding-left: 22px;
        background: url() no-repeat left center;
        background-size: 16px;
    }
    .personal-fans-attention-btn {
        padding: 15px 10px 25px;
        display: -webkit-box;
        color: #000;
        font-size: 14px;
    }
    .personal-fans-attention-btn a {
        display: block;
        font-size: 13px;
        color: #999;
        text-align: center;
        -webkit-box-flex: 1;
        border: .5px solid #e5e5e5;
        border-radius: 4px;
        height: 42px;
        line-height: 42px;
    }
    .personal-fans-attention-btn .attention {
        margin-right: 10px;
    }
    .personal-fans-attention-btn .attention span {
        background: url() no-repeat 0;
        background-size: 14px;
        padding-left: 18px;
    }
    .personal-fans-attention-btn .fans span {
        background: url() no-repeat 0;
        background-size: 14px;
        padding-left: 18px;
    }
    .personal-lsit {
        padding-top: 10px;
    }
    .personal-lsit .box {
        /*display: -webkit-box;*/
        overflow: hidden;
        background: #fff;
    }
    .personal-lsit_btn {
        height: 48px;
        width: 100%;
        border-bottom: 1px solid #efeff4;
        background: #fff;
        position: relative;
        display: block;
        padding: 0 14px;
        box-sizing: border-box;
        overflow: hidden;
    }
    .personal-lsit_btn p {
        height: 48px;
        line-height: 48px;
        margin: 0 auto;
        color: #333;
        text-indent: 25px;
    }
    .personal-lsit_btn p {
        position: relative;
    }
    .personal-lsit_btn p .new_icon {
        display: inline-block;
        position: absolute;
        top: 11px;
        right: 0;
    }
    .personal-lsit_btn p .new_icon img {
        display: block;
        width: 30px;
    }
    .personal-lsit_btn p.p1 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p2 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p5 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p6 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p8 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p13 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p18 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p19 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p20 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-lsit_btn p.p21 {
        background: url() no-repeat top;
        background-size: 28px;
    }
    .personal-disclaimer {
        height: 40px;
        line-height: 40px;
        text-align: center;
        width: 100%;
        display: block;
        font-size: 12px;
        color: #999;
        text-decoration: underline;
        margin: 0 auto;
        margin-bottom: 70px;
        margin-top: 5px;
    }
    .scanimg{
        width: 28px;
        height:28px;
        position: absolute;
        right: 76px;
        top: 32px;
    }
</style>